<template>
  <div>
      PROCESS
  </div>
</template>

<script>
import base from "./base";
export default {
  extends: base,
  data: {
    timeStart: null
  },
  computed: {
    submitPath() {
      return this.model.path;
    }
  },
  methods: { 
    onTrigger() {
      this.$Modal.confirm({
        title: "确认操作",
        content: "确认执行" + this.model.name + "操作",
        onOk: () => {
          this.actionActive();
        },
        onCancel() {
          this.actionCancel();
        }
      });
    },
    onActive() {
      this.timeStart = new Date();
      return this.submit(this.submitPath, this.scopeParam, {
        method: this.actionParam.method || "post",
        param: this.scopeParam
      });
    },
    onSuccess(text) {
      if (this.actionParam.result_show) {
        //临时处理 待解决 与确认框冲突，太快弹出会导致成功窗口被同时关闭
        setTimeout(() => {
          this.$Modal.success({
            title: "执行器执行成功",
            content: this.resultContent()
          });
        }, 300);
      } else {
        this.$Message.success(text || `${this.model.name} 操作成功`);
      }
    },
    resultContent() {
      var text =
        typeof this.successData.data === "object"
          ? JSON.stringify(this.successData.data, null, 2)
          : this.successData.data;
      var content = `<p>${text}</p>`;
      if (this.actionParam.result_show_time) {
        var time = new Date() - this.timeStart;
        content =
          `<h4>执行时间:<span class="text-success">${time}ms</span></h4>` + content;
      }
      return content;
    }
  }
};
</script>

<style>

</style>
